package sink

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)

const (
	DBHost     = "localhost"
	DBPort     = ":3306"
	DBUser     = "root"
	DBPwd      = "root"
	DBDatabase = "go"
)


type MysqlSink struct {
	database *sql.DB
}

func NewMysqlSink() (sink MysqlSink, err error) {
	dbConnection := fmt.Sprintf("%s:%s@tcp(%s%s)/%s", DBUser, DBPwd, DBHost, DBPort,
		DBDatabase)
	db, err := sql.Open("mysql", dbConnection)
	if err != nil {
		return
	}
	sink = MysqlSink{}
	sink.database = db
	return
}

func (sink MysqlSink) Close() {
	sink.database.Close()
}





//func GetSheet(single music.SongSheetModel)(singles []music.SongSheetModel,err error )  {
//	defer Db.Close()  // 注意这行代码要写在上面err判断的下面
//	err = Db.Select(&singles, "select song_sheet_id from m_song_sheet where song_sheet_id = ? ", single.Song_sheet_id)
//	if err != nil {
//		fmt.Println("exec failed, ", err)
//		return
//	}
//	return singles,nil
//}
//func InSheet(single music.SongSheetModel) (err error) {
//	defer Db.Close()  // 注意这行代码要写在上面err判断的下面
//	_, err = Db.Exec("insert into m_song_sheet(song_sheet_id,sheet_name,create_name,track_count) values (?,?,?,?)",
//		single.Song_sheet_id, single.Sheet_name,single.Create_name,single.TrackCount)
//	if err != nil {
//		return
//	}
//	return
//}


